﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Groove.Winform
{
    public partial class UcMusicOnPcButton : UserControl
    {
        private MouseState _mouseState = MouseState.Out;
        public event EventHandler ControlClicked;

        public UcMusicOnPcButton()
        {
            InitializeComponent();
            RegistMouseHoverEvents();
            RegistMouseClickedEvents();
        }

        private void RegistMouseClickedEvents()
        {
            Click += UcMusicOnPcButton_Click;
            picIcon.Click += UcMusicOnPcButton_Click;
            lblText.Click += UcMusicOnPcButton_Click;
        }

        private void UcMusicOnPcButton_Click(object sender, EventArgs e)
        {
            ControlClicked?.Invoke(this, e);
        }

        private void RegistMouseHoverEvents()
        {
            MouseEnter += UcMusicOnPcButton_MouseEnter;
            picIcon.MouseEnter += UcMusicOnPcButton_MouseEnter;
            lblText.MouseEnter += UcMusicOnPcButton_MouseEnter;
            MouseLeave += UcMusicOnPcButton_MouseLeave;
            picIcon.MouseLeave += UcMusicOnPcButton_MouseLeave;
            lblText.MouseLeave += UcMusicOnPcButton_MouseLeave;
        }

        private void UcMusicOnPcButton_MouseLeave(object sender, EventArgs e)
        {
            SetUIColor(MouseState.Out);
        }     

        private void UcMusicOnPcButton_MouseEnter(object sender, EventArgs e)
        {
            
            SetUIColor(MouseState.Hover);
        }

        private void SetUIColor(MouseState mouseState)
        {
            if (_mouseState == mouseState) return;
            _mouseState = mouseState;
            BackColor = _mouseState == MouseState.Out ? Color.FromArgb(23, 23, 23) : Color.FromArgb(45, 45, 45);
            picIcon.Image = _mouseState == MouseState.Out ? Properties.Resources.Playlist : Properties.Resources.PlaylistYellow;
            lblText.ForeColor = _mouseState == MouseState.Out ? Color.White : Color.FromArgb(255, 130, 50);
        }
    }
}
